Getting Started
Our NonStop IT Team
In this tutorial, we will be creating a Java application on Apache Tomcat to help the NonStop IT Team with their Tickets. The application will manage new tickets, and edit existing tickets.
We will need 2 tables for this - User and Ticket.
The Ticket table will be located in the SQL/MX, and the User table will be located in the MySQL.
Functions To Complete
At the end of this tutorial, our Java application should be able to
- Create new Tickets, if they are an existing user
- Update existing Tickets if the tickets exist
Setting up our development machine
Before we start coding, we are going to do some prep work for our development machines.
Check and make sure that you have the following:
1. SQLMX - While we're keep on working on the fault-tolerant features of this database, come speak with us for a demo and a good feel of our efforts!
2. Java - Download Java for Windows
3. MySQL - Download MySQL for Windows
4. Apache Tomcat - step-by-step guide down in the next segment.
For this tutorial, we are using MySQL-8.0.30-winx64 package, Java Openjdk version 18.0.1 - development is on a Windows OS.
How to Install Apache Tomcat
1.0 Creating a directory for this tutorial
Create a directory and name it as ItTicketing to store and keep track of the project files.
1.1 Downloading and Installing Tomcat
For Windows:
-
Go to Tomcat Downloads and search for "Downloads" under Tomcat 10.x Released segment.
-
Scroll down to the Source Code Distributions segment download the zip file.
-
Unzip and extract the downloaded file into the ItTicketing project directory.
-
Rename the extracted folder to \tomcat. i.e
C:\ItTicketing\tomcat
Tomcat's Sub-directories
- bin - contains binaries and scripts to startup and shutdown the server.
- conf - contains the system-wide configuration files such as server.xml, web.xml and content.xml.
- webapps - contains the webapps to be deployed. You can place WAR files for deployment in this folder.
- lib - contains Tomcat's system-wide library JAR files, accessible by all webapps. All other JAR files such as JDBC drivers will be placed here.
- logs - contains Tomcat's log files with error messages as generated.
- ** work** - Tomcat's working directory used by JSP for JSP-to-Servlet conversion.
1.2 Creating the JAVA_HOME environment variable
For Windows:
-
Search for "Edit System Variables" on your machine.
-
Create an environment variable called "JAVA_HOME" and set it to the JDK installed directory.
1.3 Configuring the Tomcat Server
The Tomcat configuration files in XML format are located in teh "conf" sub-directory of the Tomcat installed directory. i.e server.xml, web.xml, content.xml
Create a backup copy of the configuration files.
1.3.1 Setting the TCP Port Number - \conf\server.xml
-
Open the
\conf\server.xml
file using a text editor (such as VSCode, Sublime Text or Atom). -
Change the port variable in the "Connector" to be "port="2020"".
A "Connector" represents an endpoint by which requests are received and responses are returned.
<Connector port="2020" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />
1.3.2 Enabling Directory Listing - \conf\web.xml
-
Open the
\conf\web.xml
file using a text editor. -
Change the param-value to false to enable directory listing.
...
<init-param>
<param-name>listings</param-name>
<param-value>false</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
1.3.3 Enabling Automatic Reload - \conf\context.xml
-
Open the
\conf\context.xml
file using a text editor. -
Add reloadable="true", crossContext="true", and parallelAnnotationScanning="true" into the Context attribute.
<Context reloadable="true" crossContext="true" parallelAnnotationScanning="true">
1.4 Starting the Tomcat Server
1.4.1 Starting the Server
For Windows:
- Launch a Command Shell console and navigate into the Tomcat folder's
bin
.
> _cd C:\ItTicketing\tomcat\bin_
>
> _startup_
1.4.2 Starting a Client to access the Server
-
Start a browser and connect using the link - http://localhost:2020.
-
The Tomcat server's welcome page should appear.
-
To view other servlet examples, try navigating to http://localhost:2020/examples.
1.4.3 Shutting down the Server
For Windows:
- Press Ctrl+C on the Tomcat console OR
- Open another Command Shell console and run the
shutdown.bat
script.
> _cd C:\ItTicketing\tomcat\bin_
>
> _shutdown_
1.5 Developing and Deploying a "Hello World!" Web App
1.5.1 Creating a directory structure for the application - \hello
Let's create our first Hello World webapp with Tomcat.
- Create a new folder
hello
in thewebapps
directory, aWEB-INF
in thehello
folder, and aclasses
folder inWEB-INF
->\tomcat\webapps\hello
> _cd C:\ItTicketing\tomcat\webapps_
>
> _mkdir hello_
>
> _cd C:\ItTicketing\tomcat\webapps\hello_
>
> _mkdir WEB-INF_
>